Web Services in detail

Neel Vikmani
codeburst
Published in
6 min readJun 15, 2019

--

Photo by Luca Bravo on Unsplash

This article explains everything that you need to know about web services.

A lot of you may have heard these things, but actually don’t know what they are and how they work. Well, just like any other concept, they are easy to understand if you interpret it right. I will try to explain it in the best possible way, right from the basics, differentiating it from many other similar concepts and why and are they used extensively today.

Firstly, understand the difference between a website and web application

A website is a collection of web pages which are static. Static here means that the data or information is hard-coded and do not require any inputs from user or communications with database. Example of static website can be any small business website which has only services, contact us pages with content embedded in HTML itself.

Web application, on the other hand are dynamic websites which constantly require communicating with databases or back-end services for data or information to be presented to the end user. Example of a web applications are medium.com, amazon.com, etc.

A thought

Do you think that the massive applications such as Gmail, Uber use single programming language for all their development. There are thousands of services running each second on their data centers to cope up with users demands and requests. These services may be executing various programs written in various programming languages and even run on different platforms. Since there are more than one languages and technologies used in developing one big web application, you might wonder how do these different programs that are written in different languages communicate with each other. If each language has their own syntax and way of interpreting things, how do they understand what programs written in different application wish to communicate.

Is there any standard way that all different programs can use to communicate with each other? (Just like each country have their own native languages, but they can use English to communicate with anyone outside their country)

The answer is Yes. There is, and this is what we call a Web Service.

Web service enables communication among different applications over web using some standard protocol/method. Using web services, two different applications can talk to each other and exchange information.

Typically, a web service provider, who wants to enable its functionality to be used by other applications, develops a service and makes it available over Internet. Any application can request the service to the server where it is hosted and the server responds to that request.

Two notable concepts come into picture here — WSDL and UDDI. Putting in simple terms, WSDL(Web Services Description Language) provides information about the functionalities of any particular web service, and UDDI(Universal Description, Discovery, and Integration) is kind of a distributed directory of web services, where the server can publish their services, and clients can lookup to find any service. So, UDDI document can have entries of multiple web services, and each web service may have it’s own WSDL document.

The question arises again that how these applications communicate. The two important factors are Medium through which the data or information flows from one application to another, and Format in which the information is transferred. For example, while speaking over a telephone, medium is the phone and format is English or any language that both of you know.

Two formats for communication between applications are universally accepted — XML and JSON.

Below is the example of representation of students data using JSON and XML.

Lets say there are 2 student records, each record has student name, email and city.

XML representation

<students>
<student>
<name>John</name>
<email>john@xyz.com</email>
<city>Boston</city>
</student>
<student>
<name>Julie</name>
<email>julie@xyz.com</email>
<city>London</city>
</student>
</students>

JSON representation

{"students":
[
{"name":"John", "email":"john@xyz.com", "city":"Boston"},
{"name":"Julie", "email":"julie@xyz.com", "city":"London"}
]
}

Clearly, you can see that JSON is more easy to write and understand.

JSON is actually used on larger scale than XML because it is light weight and easy to understand.

Now, coming to the medium through which the data is transferred. Web services use HTTP(Hypertext Transfer Protocol) for sending requests and responses over web.

HTTP uses request/response technique, that is, communication or transfer of information between web server and browser is done through HTTP request and response packets.

For example, web server is where all files related to website are present; the browser or client sends request for HTML page, server responds with requested page. Similarly, browser may request for some information to the server by sending HTTP request, and server processes the request and provides appropriate responses as HTTP response in the format(XML or JSON) discussed above.

Now that you know the fundamental concepts of web service, let’s dig into the types of web services

Types of Web Service

Primarily, there are two types of web services-

  • SOAP web services
  • RESTful web services

In SOAP(Simple Object Access Protocol) based web service, all the information exchange happens over a single common format — XML. These XML based messages have a defined structure, which is known as SOAP Message. Each of this SOAP message consists of Envelope, which has a header and body.

Remember that web services are used to communicate between two different applications, platforms, or browser and server, so these services need to have all information required for efficient transmission of any message.

In SOAP envelope, header provides information about message itself, and also includes routing information, authentication information, if any. Body contains the actual data that needs to be sent.

RESTful web services communicates between application using REST principles. REST(Representational State Transfer) is an architectural style which defines the way in which communication happens between two different application. And the way in which it happens is uniform and stateless.

Two major principles of REST are uniform interface and statelessness.

Uniform interface means everything in RESTful web service is a resource. Resource can be a data, information or any block of data. This means that there is no distinguished part which cannot be accessed or accessed differently, everything is accessed by a URI(Uniform Resource identifier). Also, RESTful web services makes use of HTTP methods for exchange of information. Oh sorry, I meant exchange of resource :P.

For example: HTTP methods like GET, PUT, POST and DELETE can be used to request some resource specified in URI itself.

Suppose I want to get details of all student records from xyz website.

GET www.xyz.com/students

or if I need detail of a particular student with ID 12345

GET www.xyz.com/student/12345

Similarly, PUT can be used to update the existing resource details, POST can be used to add new resource and DELETE can be used to delete a resource. In above example, I can use PUT method and specify the updated value of any detail, like name or email in my body. Similarly, I can use POST method to add new student record and DELETE method to delete a student record.

If you are building a web service or an API in a RESTful manner, you must specify the appropriate functionality and response that you want to give for any given HTTP requests received through URI.

Stateless communication means there is no need of previous information or data that is required to send current request or response. Every request or response contains all the information itself and does not rely on any previous state of messages.

REST also supports caching and layered approach. Various layers of components can be added between client and server like proxy server, gateways, etc. Also, it supports XML and JSON format, whereas SOAP only supports XML. Because of all these principles and differences, REST is more preferred over SOAP.

Conclusion

Web services are widely used today for communication and exchanging data between any disparate applications or platforms. Technology is growing at a faster rate and more connectivity and seamless integration of services ensures greater experience and value for users. RESTful web services are dominant for most reasons, and REST is widely used in developing APIs and web services.

Thank you for reading this article.

I hope you enjoyed reading about web services and now understand the concept. You can also checkout my article about web development tips and resources.

Feel free to contact me if you need any help or discuss something. I would love to connect with you.

You can connect with me on Medium, Linkedin and Github.

--

--